package com.ys.service.report.impl;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.ys.entity.report.TcoBusinessDataGs;
import com.ys.mapper.report.ReportMapper;
import com.ys.mapper.report.TcoBusinessDataGsMapper;
import com.ys.service.report.TcoBusinessDataGsService;
import com.ys.vo.R;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
//数据统计店铺清单
@Service("tcoBusinessDataGsService")
public class TcoBusinessDataGsServiceImpl implements TcoBusinessDataGsService {
	private static final Logger logger = LoggerFactory.getLogger(TcoBusinessDataGsServiceImpl.class);
	@Autowired
	private TcoBusinessDataGsMapper tcoBusinessDataGsMapper;


	/**
	 * 新增
	 */
	@Override
	public R add(String vgsbm)throws Exception{

		int isAdded = new TcoBusinessDataGs().setVgsbm(vgsbm).count();
		if(isAdded>0){
			return R.error("该公司已经配置过");
		}

		TcoBusinessDataGs entity = new TcoBusinessDataGs()
				.setVgsbm(vgsbm)
				.setStatus(1);
		tcoBusinessDataGsMapper.insert(entity);

		return R.ok();

	}


	/**
	 * 删除
	 */
	@Override
	public R del(JSONArray dataList)throws Exception{

		for(int i=0;i<dataList.size();i++){
			JSONObject info = dataList.getJSONObject(i);
			Long id = info.getLong("id");
			tcoBusinessDataGsMapper.deleteTrue(id);
		}
		return R.ok();

	}
}
